package com.example.pma.controllers;

import com.example.pma.dao.ResumeRepository;
import com.example.pma.entities.Resume;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("resumes")
public class ResumeController {

    @Autowired
    ResumeRepository resumeRepository;

    @GetMapping
    public String displayPosition(Model model){

        List<Resume> resumes = resumeRepository.findAll();
        model.addAttribute("resumes",resumes);
        return "resumes/list-resumes";
    }

    @GetMapping("/new")
    public String displayPositionForm(Model model){

        Resume aResume = new Resume();
        model.addAttribute("resume",aResume);
        return "resumes/new-resume";
    }

    @PostMapping("/save")
    public String createPosition(Model model,Resume resume){


        resumeRepository.save(resume);

        return "redirect:/resumes";

    }
}
